/*
 * Copyright 2007, Sualeh Fatehi <sualeh@hotmail.com>
 * 
 * This work is licensed under the Creative Commons Attribution 3.0 License. 
 * To view a copy of this license, visit 
 * http://creativecommons.org/licenses/by/3.0/ 
 * or send a letter to 
 * Creative Commons
 * 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
 */
package sf.dao;


import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public final class DataAccessOperator<T>
  extends HibernateDaoSupport
{

  public DataAccessOperator(final SessionFactory sessionFactory)
  {
    setSessionFactory(sessionFactory);
  }

  public void delete(final T entity)
  {
    getHibernateTemplate().delete(entity);
  }

  public T find(final Class<T> clazz, final long id)
  {
    return (T) getHibernateTemplate().load(clazz, id);
  }

  public List<T> findAll(final Class<T> clazz)
  {
    return getHibernateTemplate().find("from " + clazz.getName());
  }

  public void save(final T entity)
  {
    getHibernateTemplate().saveOrUpdate(entity);
  }

}
